import useDictStore from "@/store/modules/dict";
import { getDicts } from "@/api/system/dict/data";

/**
 * 获取字典数据
 */
export function useDict(...args) {
  const res = ref({});
  return (() => {
    args.forEach((dictType, index) => {
      res.value[dictType] = [];
      const dicts = useDictStore().getDict(dictType);
      if (dicts) {
        res.value[dictType] = dicts;
      } else {
        getDicts(dictType).then((resp) => {
          res.value[dictType] = resp.data.map((p) => ({ label: p.dictLabel, value: p.dictValue, elTagType: p.listClass, elTagClass: p.cssClass }));
          useDictStore().setDict(dictType, res.value[dictType]);
        });
      }
    });
    return toRefs(res.value);
  })();
}
/**
 * 还款方式类型
 */
export function loanTypes(type) {
  switch (type) {
    case 1:
      return "个人信用";
    case 2:
      return "个人分期";
    case 3:
      return "个人抵押";
    case 4:
      return "企业信用";
    case 5:
      return "企业分期";
    case 6:
      return "企业租赁";
    default:
      return type;
  }
}
/**
 * 还款方式类型
 */
export function methodType(type) {
  switch (type) {
    case 1:
      return "等额本息";
    case 2:
      return "等额本金";
    case 3:
      return "等本等息";
    case 4:
      return "先息后本";
    case 5:
      return "一次性还息付本";
    default:
      return type;
  }
}
/**
 * 放款通道
 */
export function channelType(type) {
  switch (type) {
    case 1:
      return "委托银行放款";
    case 2:
      return "金融机构放款";
    default:
      return type;
  }
}
/**
 * 状态
 * 1-初审通过；2-复审通过；3-复审驳回；4-复审终止；5-终审通过；
 * 6-终审驳回；7-终审终止;8-放款审批；9-放款处理;10-已放款
 */
export function statusType(type) {
  switch (type) {
    case 1:
      return "初审通过";
    case 2:
      return "复审通过";
    case 3:
      return "复审驳回";
    case 4:
      return "复审终止";
    case 5:
      return "终审通过";
    case 6:
      return "终审驳回";
    case 7:
      return "终审终止";
    case 8:
      return "放款审批";
    case 9:
      return "放款处理";
    case 10:
      return "已放款";
    default:
      return type;
  }
}
/**
 * 检查方式  1-电话检查；2-实地检查
 */
export function methodWayType(type) {
  switch (type) {
    case 1:
      return "电话检查";
    case 2:
      return "实地检查";
    default:
      return type;
  }
}
/**
 * 检查原因  1-首次检查；2-日常检查；3-逾期检查；4-其它
 */
export function causeType(type) {
  switch (type) {
    case 1:
      return "首次检查";
    case 2:
      return "日常检查";
    case 3:
      return "逾期检查";
    case 4:
      return "其它";
    default:
      return type;
  }
}
/**
 * 检查原因 1-正常贷款；2-关注贷款；3-次级贷款；4-可疑贷款；5-损失贷款
 */
export function classifyType(type) {
  switch (type) {
    case 1:
      return "正常贷款";
    case 2:
      return "关注贷款";
    case 3:
      return "次级贷款";
    case 4:
      return "可疑贷款";
    case 5:
      return "损失贷款";
    default:
      return type;
  }
}
/**
 * 预警发送方式 (1-短信；2-邮件)
 */
export function wayType(type) {
  switch (type) {
    case 1:
      return "短信";
    case 2:
      return "邮件";
    default:
      return type;
  }
}
/**
 * 预警阶段(1-即将到期的贷款；2-已经逾期的贷款)
 */
export function warningStageType(type) {
  switch (type) {
    case 1:
      return "即将到期的贷款";
    case 2:
      return "已经逾期的贷款";
    default:
      return type;
  }
}

/*贷前贷中使用 */
//状态转译
export function auditStatus(status) {
  switch (status) {
    case 1:
      return "初审通过";
    case 2:
      return "复审通过";
    case 3:
      return "复审驳回";
    case 4:
      return "复审终止";
    case 5:
      return "终审通过";
    case 6:
      return "终审驳回";
    case 7:
      return "终审终止";
    case 8:
      return "放款审批";
    case 9:
      return "放款处理";
    case 10:
      return "已放款";
  }
}

//弹窗审核结果转译
export function auditResult(status) {
  switch (status) {
    case 1:
      return "通过";
    case 2:
      return "驳回";
    case 3:
      return "拒绝";
  }
}
//弹窗审核类型转译
export function auditType(status) {
  switch (status) {
    case 1:
      return "初审";
    case 2:
      return "复审";
    case 3:
      return "终审";
  }
}
